import { createStore } from "vuex";

const store = createStore({
	state() {
		return {
			point: "http://localhost:8081",
			user: JSON.parse(window.sessionStorage.getItem("user")),
		};
	},
	mutations: {
		login(state, user) {
			state.user = user;
			window.sessionStorage.setItem("user", JSON.stringify(user));
		},
		logout(state) {
			state.user = null;
			window.sessionStorage.removeItem("user");
		},
		loginAdmin(state) {
			state.user = {
				isAdmin: true,
			};
			window.sessionStorage.setItem("user", JSON.stringify(state.user));
		},
	},
	actions: {},
	getters: {
		user(state) {
			return state.user;
		},
		point(state) {
			return state.point;
		},
	},
});
export default store;
